package UI;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.ConnectException;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.ArrayList;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import ALGORITHM.Result;
import COMP.ExportCsv;
import COMP.ExportPDF;
import COMP.Exportxls;
import COMP.ImageComponent;
import COMP.Importkinddata;
import COMP.OpenFileFilter;
import COMP.Path_Loader;
import COMP.PopUpTable;
import COMP.TabTable;
import COMP.imgBtn;
import DB.DAO;
import DB.VO;
import au.com.bytecode.opencsv.CSVReader;

public class Main {
	private static JFrame frmHsproject;
	private VO vo = new VO();
	private DAO dao = new DAO(vo);

	private SHJTree leftJTree = new SHJTree("건축 요소", true, vo);
	private SHJTree rightJTree = new SHJTree("시스템", false, vo);
	private SHJTabbedPane tabbedPane = new SHJTabbedPane();
	// private JPanel bottomBtnPnl = new JPanel();
	private imgBtn btnExport = new imgBtn("Img/main_butt_export.png",
			"Img/main_butt_export_click.png", "Img/main_butt_export_over.png");
	private imgBtn btnGraph = new imgBtn("Img/main_butt_graph.png",
			"Img/main_butt_graph_click.png", "Img/main_butt_graph_over.png");
	private imgBtn btnWindowsClose = new imgBtn("Img/chart_butt_x.png");
	private imgBtn btnWindowsIconified = new imgBtn("Img/chart_butt_-.png");

	// private int[] frmHsprojectSize = {840, 580};
	// private int[] leftJTreePositon = {29, 100, 173, 454};
	// private int[] rightJTreePositon = {638, 100, 173, 454};
	// private int[] tabbedPanePositon = {210, 127, 420, 350};
	// private int[] btnExportPositon = {208, 477, 210, 60};
	// private int[] btnGraphPositon = {423, 477, 210, 60};

	private int[] frmHsprojectSize = { 915, 740 };
	private int[] leftJTreePositon = { 40, 120, 192, 624 };
	private int[] rightJTreePositon = { 705, 120, 192, 624 };
	private int[] tabbedPanePositon = { 229, 147, 460, 490 };
	private int[] btnExportPositon = { 229, 634, 230, 60 };
	private int[] btnGraphPositon = { 459, 634, 230, 60 };

	private PopUpSelectProject selectProject;
	private PopUpSelectThreeProject popSTP;
	private PopUpInsertProject popIP;
	private PopUpTable popTable;
	private PopUpInsertEquipment popIE;
	private PopUpEconomics popEconomics;
	private PopUpTotalEnergySpend popTES;
	private PopUp3DChart pop3DChart;
	private PopUpNPVChart popNPVChart;
	private PopUpOptimizationTable popOTable;
	private PopUpResultTable popRTable;
	private PopUpOTOption popUpOTOption;
	private PopUpBE popBE;
	private PopUpEetc popEetc;
	private PopUpTableEdit pte;
	private int projecttype = 0; // Bess:1, model:2, input:3
	private int prjIdx = -1; // project index
	private int sysIdx = -1; // system index
	private int checkin = 0;
	private int selectedZoneNum = 0;
	private int selectedWallNum = 0;
	private boolean lcomboBoxSelected = true;
	private boolean rcomboBoxSelected = true;
	private boolean lisComboBoxin = false;
	private boolean risComboBoxin = false;
	private boolean isLeftTreeSelectnull = false;
	private boolean isRightTreeSelectnull = false;
	private boolean passive = false;
	private boolean system = false;
	private boolean light = false;
	private boolean newenergy = false;
	// private boolean autosave = false;
	private int percentage = 0;
	private String projectname;
	private String systemName;
	private String selectedpriority;
	private String[] selectProjects;
	final byte STATE_SAVE = 1;
	final byte STATE_Load = 0;
	private int lastindx;

	private JFileChooser chooser;

	private Result resultset;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			javax.swing.UIManager
					.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
			// javax.swing.UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
			// 별로임
			// javax.swing.UIManager.setLookAndFeel("com.birosoft.liquid.LiquidLookAndFeel");
			// javax.swing.UIManager.setLookAndFeel("net.infonode.gui.laf.InfoNodeLookAndFeel");
			// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.smart.SmartLookAndFeel");
			// 별로임
			// javax.swing.UIManager.setLookAndFeel("com.jtattoo.plaf.mcwin.McWinLookAndFeel");
			// 별로임
		} catch (ClassNotFoundException e1) {
			e1.printStackTrace();
		} catch (InstantiationException e1) {
			e1.printStackTrace();
		} catch (IllegalAccessException e1) {
			e1.printStackTrace();
		} catch (UnsupportedLookAndFeelException e1) {
			e1.printStackTrace();
		}
		new Main();
	}

	/**
	 * Create the application.
	 */
	public Main() {
		initialize();
		start();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frmHsproject = new JFrame();
		frmHsproject
				.setTitle("HDC–OTRE (Optimisation Tool for Renewable Energy)");
		frmHsproject.setSize(frmHsprojectSize[0], frmHsprojectSize[1]);
		frmHsproject.setLocationRelativeTo(null);
		frmHsproject.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmHsproject.setUndecorated(true);
		frmHsproject.getContentPane().setLayout(null);
		// MainName();
		try {
			dao.load_wall_price();
			dao.load_window_price();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		MainLeftJTree();
		MainRightJTree();
		MainTabbedPane();
		MainBottomButtons();
		MainBackGround();
		frmHsproject.setResizable(false);
		Main_Logo ML = new Main_Logo("Img/popup_logo.png", 900, 700, 4000);
		ML.run();

		frmHsproject.setVisible(true);
	}

	public void MainBackGround() {
		ImageComponent mainBG = new ImageComponent(new ImageIcon(
				"Img/main_bg.png").getImage());
		mainBG.setBounds(0, 0, frmHsprojectSize[0], frmHsprojectSize[1]);
		mainBG.setOpaque(false);
		frmHsproject.getContentPane().add(mainBG);

	}

	/**
	 * 메인화면에 이름부분 출력
	 */
	public void MainName() {
		// OTRE 한글이름
		JLabel lblTitle = new JLabel("신재생 에너지 최적 설계 툴");
		lblTitle.setBounds(215, 12, 459, 60);
		lblTitle.setHorizontalAlignment(JLabel.CENTER);
		lblTitle.setFont(new Font("굴림", Font.BOLD, 30));
		frmHsproject.getContentPane().add(lblTitle);

		// OTRE 영어이름
		JLabel lblEngTitle = new JLabel(
				"HDC–OTRE (Optimisation Tool for Renewable Energy)");
		lblEngTitle.setBounds(215, 65, 459, 40);
		lblEngTitle.setHorizontalAlignment(JLabel.CENTER);
		lblEngTitle.setFont(new Font("굴림", Font.BOLD, 16));
		frmHsproject.getContentPane().add(lblEngTitle);
	}

	/**
	 * 프로젝트와 관련된 차트 콤보박스를 출력
	 */
	public void MainLeftJTree() {
		// 메인 왼쪽부분 출력
		leftJTree.setBounds(leftJTreePositon[0], leftJTreePositon[1],
				leftJTreePositon[2], leftJTreePositon[3]);
		frmHsproject.getContentPane().add(leftJTree);

		FillC1();
		leftJTree.setComboBoxItem(-1);
		prjIdx = leftJTree.getSelectedIdx();
	}

	/**
	 * 시스템과 관련된 차트 콤보박스를 출력
	 */
	public void MainTabbedPane() {
		// TabbedPane 출력
		tabbedPane.setBounds(tabbedPanePositon[0], tabbedPanePositon[1],
				tabbedPanePositon[2], tabbedPanePositon[3]);
		frmHsproject.getContentPane().add(tabbedPane);
	}

	/**
	 * 데이터가 들어갈 패널들을 담을 tabbedpane을 출력
	 */
	public void MainRightJTree() {
		// 메인 오른쪽부분 출력
		rightJTree.setBounds(rightJTreePositon[0], rightJTreePositon[1],
				rightJTreePositon[2], rightJTreePositon[3]);
		frmHsproject.getContentPane().add(rightJTree);

		FillC2();
		rightJTree.setComboBoxItem(-1);
		sysIdx = rightJTree.getSelectedIdx();
	}

	/**
	 * 메인 하단부에 들어갈 두 버튼을 출력
	 */
	public void MainBottomButtons() {
		// 하단에 들어갈 두개의 버튼;
		btnExport.setBounds(btnExportPositon[0], btnExportPositon[1],
				btnExportPositon[2], btnExportPositon[3]);
		frmHsproject.getContentPane().add(btnExport);
		btnGraph.setBounds(btnGraphPositon[0], btnGraphPositon[1],
				btnGraphPositon[2], btnGraphPositon[3]);
		frmHsproject.getContentPane().add(btnGraph);
		btnWindowsClose.setBounds(895, 7, 10, 10);
		btnWindowsClose.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			
//				if(leftJTree.getSelectedIdx() != -1){
//					Fill1();
//				}
//				
//				if(rightJTree.getSelectedIdx() != -1){
//					Fill7();
//				}
				
				System.exit(0);
			}
		});
		frmHsproject.add(btnWindowsClose);
		btnWindowsIconified.setBounds(883, 7, 10, 10);
		btnWindowsIconified.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				frmHsproject.setExtendedState(JFrame.ICONIFIED);
			}

		});
		frmHsproject.add(btnWindowsIconified);

	}

	public void start() {
		leftJTreeEvent();
		rightJTreeEvent();
		tabbedPaneEvent();
		projectSummaryEvent();
		zoneEvent();
		wallEvent();
		windowEvent();
		buildingEquipmentEvent();
		equipmentetcEvent();
		renewalEnergyEvent();
		economicsEvent();
		bottomButtonsEvent();
	}

	public void leftJTreeEvent() {
		leftJTree.addBtnActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				lcomboBoxSelected = false;
				if (prjIdx != -1 && leftJTree.getSelectedIdx() != -1) {
					JOptionPane jop = new JOptionPane("건축요소 작업 내용을 저장 하시겠습니까?",
							JOptionPane.PLAIN_MESSAGE,
							JOptionPane.YES_NO_OPTION, null);
					JDialog dialog = jop.createDialog(frmHsproject, "Save");
					dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
					dialog.setVisible(true);
					int selecteValue = Integer.valueOf(jop.getValue()
							.toString());

					if (selecteValue == JOptionPane.YES_OPTION) {
						Fill1();
					}

				}

				while (true) {
					projectname = (JOptionPane.showInputDialog(frmHsproject,
							"새 건축요소의 이름을 입력하세요."));

					if (projectname == null) {
						lcomboBoxSelected = true;
						return;
					} else if (FillF1(projectname)
							|| projectname.trim().equals("")) {
						continue;
					} else {
						Fill12();
						leftJTree.setComboBoxItem(-1);
						prjIdx = -1;
						Fill2();
						popIP = new PopUpInsertProject(frmHsproject);
						popIPEvent();
						popIP.setVisible(true);
						return;
					}
				}
			}
		});

		leftJTree.delBtnActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (isLeftTreeSelectnull == true) {
					return;
				}

				prjIdx = leftJTree.getcomboBoxSize();
				if (leftJTree.getSelectedIdx() != -1) {
					lcomboBoxSelected = false;
					int selectedbtn = JOptionPane.showConfirmDialog(
							frmHsproject, "건축요소를 삭제 하시겠습니까?", "삭제",
							JOptionPane.YES_NO_OPTION);
					if (selectedbtn == JOptionPane.YES_OPTION) {
						int ListIdx = leftJTree.getSelectedIdx();

						Fill2();
						Fill5();
						// autosave=false;
						leftJTree.delComboBox(ListIdx);
						leftJTree.setComboBoxItem(-1);
						prjIdx = leftJTree.getSelectedIdx();
					} else if (selectedbtn == JOptionPane.NO_OPTION) {
						lcomboBoxSelected = true;
						return;
					}
					lcomboBoxSelected = true;
				}
			}
		});

		leftJTree.comboBoxItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				checkin++;
				if (lcomboBoxSelected && !lisComboBoxin && checkin == 1) {
					lisComboBoxin = true;
					if (prjIdx != -1) {
						JOptionPane jop = new JOptionPane(
								"건축요소 작업 내용을 저장 하시겠습니까?",
								JOptionPane.PLAIN_MESSAGE,
								JOptionPane.YES_NO_OPTION, null);
						JDialog dialog = jop.createDialog(frmHsproject, "Save");
						dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
						dialog.setVisible(true);
						int selecteValue = Integer.valueOf(jop.getValue()
								.toString());
						// if (selecteValue == JOptionPane.YES_OPTION &&
						// !autosave) {
						// Fill1();
						// }

						if (selecteValue == JOptionPane.YES_OPTION) {
							Fill1();
						}
					}

					Fill2();

					int tempSelecteIndex = leftJTree.getSelectedIdx();
					Fill12();
					leftJTree.setComboBoxItem(tempSelecteIndex);

					String name = leftJTree.getSelectedItem(tempSelecteIndex);
					Fill6(name);
					checkin--;
					prjIdx = leftJTree.getSelectedIdx();
					projecteditable();
					return;
				}

				checkin--;

				if (lisComboBoxin && checkin == 0) {
					lisComboBoxin = false;
				}
			}
		});

	}

	private void leftJTreeSelectEvent() {
		leftJTree.treeListener(new TreeSelectionListener() {
			public void valueChanged(TreeSelectionEvent e) {
				Object selectComponent = e.getPath().getLastPathComponent();
				int n1Size = leftJTree.getN1().size();
				for (int i = 0; i < n1Size; i++) {
					if (leftJTree.getN1().get(i).equals(selectComponent)) {
						tabbedPane.showPnl("zone");
						tabbedPane.getPnlZoneControl().setView("Zone");
					}
				}
				int n2Size = leftJTree.getN2().size();
				for (int i = 0; i < n2Size; i++) {
					if (leftJTree.getN2().get(i).equals(selectComponent)) {
						tabbedPane.showPnl("zone");
						tabbedPane.getPnlZoneControl().setView("Wall");
					}
				}
				int n3Size = leftJTree.getN3().size();
				for (int i = 0; i < n3Size; i++) {
					if (leftJTree.getN3().get(i).equals(selectComponent)) {
						tabbedPane.showPnl("zone");
						tabbedPane.getPnlZoneControl().setView("Window");
					}
				}
			}
		});
	}

	public void rightJTreeEvent() {
		rightJTree.addBtnActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				rcomboBoxSelected = false;
				if (sysIdx != -1 && rightJTree.getSelectedIdx() != -1) {
					JOptionPane jop = new JOptionPane("시스템 작업 내용을 저장 하시겠습니까?",
							JOptionPane.PLAIN_MESSAGE,
							JOptionPane.YES_NO_OPTION, null);
					JDialog dialog = jop.createDialog(frmHsproject, "Save");
					dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
					dialog.setVisible(true);
					int selecteValue = Integer.valueOf(jop.getValue()
							.toString());
					if (selecteValue == JOptionPane.YES_OPTION) {
						Fill7();
					}
				}

				while (true) {
					systemName = (JOptionPane.showInputDialog(frmHsproject,
							"새 시스템 이름을 입력하세요."));

					if (systemName == null) {
						rcomboBoxSelected = true;
						return;
					} else if (FillF2(systemName)
							|| systemName.trim().equals("")) {
						continue;
					} else {
						Fill13();
						rightJTree.setComboBoxItem(-1);
						sysIdx = -1;
						Fill10();
						rightJTree.addComboBox(systemName);
						sysIdx = rightJTree.getcomboBoxSize();
						rightJTree.setComboBoxItem(sysIdx - 1);
						rcomboBoxSelected = true;
						sysIdx = rightJTree.getSelectedIdx();

						rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
								tabbedPane.getPnlEetc(),
								tabbedPane.getPnlEnergy());
						rightJTreeSelectEvent();

						return;
					}
				}
			}
		});

		rightJTree.delBtnActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (isRightTreeSelectnull == true) {
					return;
				}
				sysIdx = rightJTree.getcomboBoxSize();
				if (rightJTree.getSelectedIdx() != -1) {
					rcomboBoxSelected = false;
					int selectedbtn = JOptionPane.showConfirmDialog(
							frmHsproject, "시스템 요소를 삭제 하시겠습니까?", "삭제",
							JOptionPane.YES_NO_OPTION);
					if (selectedbtn == JOptionPane.OK_OPTION) {
						int ListIdx = rightJTree.getSelectedIdx();
						Fill10();
						Fill11();
						rightJTree.delComboBox(ListIdx);
						rightJTree.setComboBoxItem(-1);
						sysIdx = rightJTree.getSelectedIdx();
					} else if (selectedbtn == JOptionPane.NO_OPTION) {
						rcomboBoxSelected = true;
						return;
					}
					rcomboBoxSelected = true;
				}
			}
		});

		rightJTree.comboBoxItemListener(new ItemListener() {
			public void itemStateChanged(ItemEvent e) {
				checkin++;
				if (rcomboBoxSelected && !risComboBoxin && checkin == 1) {
					risComboBoxin = true;
					if (sysIdx != -1) {
						JOptionPane jop = new JOptionPane(
								"시스템 작업 내용을 저장 하시겠습니까?",
								JOptionPane.PLAIN_MESSAGE,
								JOptionPane.YES_NO_OPTION, null);
						JDialog dialog = jop.createDialog(frmHsproject, "Save");
						dialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
						dialog.setVisible(true);
						int selecteValue = Integer.valueOf(jop.getValue()
								.toString());
						if (selecteValue == JOptionPane.YES_OPTION) {
							Fill7();
						}
					}

					Fill10();

					int tempSelecteIndex = rightJTree.getSelectedIdx();
					Fill13();
					rightJTree.setComboBoxItem(tempSelecteIndex);

					String name = rightJTree.getSelectedItem(tempSelecteIndex);
					Fill9(name);
					checkin--;
					sysIdx = rightJTree.getSelectedIdx();
					return;
				}

				checkin--;

				if (risComboBoxin && checkin == 0) {
					risComboBoxin = false;
				}
			}
		});

	}

	private void rightJTreeSelectEvent() {
		rightJTree.treeListener(new TreeSelectionListener() {
			public void valueChanged(TreeSelectionEvent e) {
				// 보일러 냉동기 히트펌프, 기타, 열병합 : 설비기기
				// 기타기기 : 기타기기
				// 태양광, 태양열, 지열, 풍력, 연료전지: 신재생
				String[] beList = { "보일러", "냉동기", "히트펌프", "기타", "열병합" };
				String etcList = "기타기기";
				String[] renewalList = { "태양광", "태양열", "지열", "풍력", "연료전지" };
				String selectComponent = e.getPath().getPathComponent(1) + "";
				if (selectComponent.equals(etcList)) {
					tabbedPane.showPnl("etc");
				}
				for (int i = 0; i < 5; i++) {
					if (selectComponent.equals(beList[i])) {
						tabbedPane.showPnl("be");
					}
				}
				for (int i = 0; i < 5; i++) {
					if (selectComponent.equals(renewalList[i])) {
						tabbedPane.showPnl("renewal");
					}
				}
			}
		});
	}

	private void tabbedPaneEvent() {
		tabbedPane.projectBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("project");
			}
		});
		tabbedPane.zoneBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("zone");
			}
		});
		tabbedPane.bEBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("be");
			}
		});
		tabbedPane.eEtcBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("etc");
			}
		});
		tabbedPane.renewableBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("renewal");
			}
		});
		tabbedPane.economicsBtnEvent(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.showPnl("economics");
			}
		});
	}

	public void projectSummaryEvent() {
		tabbedPane.getPnlProjectSummary().btn1Event(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else {

					PopUpEnergySpend pes1 = new PopUpEnergySpend(frmHsproject,
							vo.getFE_Graph());
					pes1.paintpnl();
					pes1.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlProjectSummary().btn2Event(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else {
					PopUpEnergySpend pes2 = new PopUpEnergySpend(frmHsproject,
							vo.getSE_Graph());
					pes2.paintpnl();
					pes2.setVisible(true);
				}
			}
		});
	}

	public void tableEditerEvent(MouseEvent e, final TabTable pnl,
			boolean[] editable, final String type) {
		if (e.getButton() == MouseEvent.BUTTON3) {
			JTable table = (JTable) e.getSource();
			final int selectRowNum = table.rowAtPoint(e.getPoint());
			final PopUpTableEdit pte = new PopUpTableEdit(frmHsproject);
			String[] temp = pnl.getData(selectRowNum);
			pte.setData(temp);
			pte.setHeaderImage(pnl.getHeader());
			pte.setColSize(pnl.getColWidth());
			pte.addHeader();
			pte.addTextField();
			pte.setTextFieldEditable(editable);
			pte.eventSaveBtn(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					DecimalFormat Dform = new DecimalFormat("###.##");
					double temp = 0;
					String[] tempdata = null;

					if (type.equals("wall")) {
						tempdata = new String[6];
						for (int i = 0; i < 6; i++) {
							tempdata[i] = pte.getData()[i];
						}

						String name = tempdata[2];
						if (tempdata[3].equals("")) {
							tempdata[3] = "0";
						}
						double area = Double.parseDouble(tempdata[3]);
						temp = vo.getWallPrice(name);
						tempdata[4] = String.valueOf(Dform.format(temp));
						tempdata[5] = String.valueOf(Dform.format(temp * area));

					} else if (type.equals("window")) {
						tempdata = new String[6];
						for (int i = 0; i < 6; i++) {
							tempdata[i] = pte.getData()[i];
						}

						String name = tempdata[1];
						if (tempdata[2].equals("")) {
							tempdata[2] = "0";
						}
						double area = Double.parseDouble(tempdata[2]);
						temp = vo.getWindowPrice(name);
						tempdata[3] = String.valueOf(Dform.format(temp));
						tempdata[4] = String.valueOf(Dform.format(temp * area));
					} else if (type.equals("zone")) {
						tempdata = new String[5];
						for (int i = 0; i < 5; i++) {
							tempdata[i] = pte.getData()[i];
						}
					}

					pnl.setRowData(tempdata, selectRowNum);
					leftJTree.setTree(tabbedPane.getPnlZone(),
							tabbedPane.getPnlWall(), tabbedPane.getPnlWindow());
					pte.dispose();
				}
			});
			pte.setVisible(true);

		}
	}

	public void zoneEvent() {
		tabbedPane.getPnlZone().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else if (projecttype == 1) {
					JOptionPane.showMessageDialog(frmHsproject,
							"베스에서불러오면 존데이터를 수정할수 없습니다.");
				} else {
					tabbedPane.getPnlZone().addRow("zone", 0, 0);

					leftJTree.setTree(tabbedPane.getPnlZone(),
							tabbedPane.getPnlWall(), tabbedPane.getPnlWindow());

				}
			}
		});
		tabbedPane.getPnlZone().eventAddTabel(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				int selectedColumn = tabbedPane.getPnlZone()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlZone().getLastColIndex();
				if (selectedColumn != lastColumn && e.getClickCount() == 2) {
					selectedZoneNum = tabbedPane.getPnlZone()
							.getSelectedRowIndex();
					tabbedPane.getPnlWall().setZoneIndex(selectedZoneNum);
					tabbedPane.getPnlZoneControl().setView("Wall");

				}
				boolean[] editable = { false, true, true, true, true, true,
						false };
				tableEditerEvent(e, tabbedPane.getPnlZone(), editable, "zone");
			}

			public void mouseReleased(MouseEvent e) {
				selectedZoneNum = tabbedPane.getPnlZone().getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlZone()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlZone().getLastColIndex();
				if (selectedColumn == lastColumn) {
					if (projecttype == 1) {
						JOptionPane.showMessageDialog(frmHsproject,
								"베스에서불러오면 존데이터를 수정할수 없습니다.");
					} else {
						tabbedPane.getPnlZone().delRow(selectedZoneNum);
						leftJTree.setTree(tabbedPane.getPnlZone(),
								tabbedPane.getPnlWall(),
								tabbedPane.getPnlWindow());

					}
				}
			}
		});
	}

	public void wallEvent() {
		tabbedPane.getPnlWall().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else if (projecttype == 1) {
					JOptionPane.showMessageDialog(frmHsproject,
							"베스에서불러오면 벽체 데이터를 수정할수 없습니다.");
				} else {
					tabbedPane.getPnlWall().addRow("wall", selectedZoneNum, 0);
					leftJTree.setTree(tabbedPane.getPnlZone(),
							tabbedPane.getPnlWall(), tabbedPane.getPnlWindow());
				}
			}
		});
		tabbedPane.getPnlWall().eventReturnBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.getPnlZoneControl().setView("Zone");
			}
		});
		tabbedPane.getPnlWall().eventAddTabel(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				int selectedColumn = tabbedPane.getPnlWall()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlWall().getLastColIndex();
				if (selectedColumn != lastColumn && e.getClickCount() == 2) {
					selectedWallNum = tabbedPane.getPnlWall()
							.getSelectedRowIndex();
					tabbedPane.getPnlWindow().setWallIndex(selectedWallNum);
					tabbedPane.getPnlWindow().setZoneIndex(selectedWallNum);
					tabbedPane.getPnlZoneControl().setView("Window");
				}
				boolean[] editable = { false, true, true, true, false, false,
						false, false };
				tableEditerEvent(e, tabbedPane.getPnlWall(), editable, "wall");
			}

			public void mouseReleased(MouseEvent e) {
				selectedWallNum = tabbedPane.getPnlWall().getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlWall()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlWall().getLastColIndex();
				if (selectedColumn == lastColumn) {
					if (projecttype == 1) {
						JOptionPane.showMessageDialog(frmHsproject,
								"베스에서불러오면 존데이터를 수정할수 없습니다.");
					} else {
						tabbedPane.getPnlWall().delRow(selectedWallNum);
						leftJTree.setTree(tabbedPane.getPnlZone(),
								tabbedPane.getPnlWall(),
								tabbedPane.getPnlWindow());

					}
				}
			}
		});

		tabbedPane.getPnlWall().eventKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char c = e.getKeyChar();

				if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
					e.consume(); // ignore event
					return;
				}

				if (tabbedPane.getPnlWall().getSelectedColIndex() == 4) {
					int rowindex = tabbedPane.getPnlWall()
							.getSelectedRowIndex();
					int columnindex = tabbedPane.getPnlWall()
							.getSelectedColIndex();
					String EBnum;

					if (c == KeyEvent.VK_BACK_SPACE) {
						EBnum = String.valueOf(tabbedPane.getPnlWall()
								.getTable().getValueAt(rowindex, columnindex));
						EBnum = (String) EBnum.subSequence(0,
								EBnum.length() - 1);
					} else {
						EBnum = String.valueOf(tabbedPane.getPnlWall()
								.getTable().getValueAt(rowindex, columnindex))
								+ c;
					}

					String cost = String.valueOf(tabbedPane.getPnlWall()
							.getTable().getValueAt(rowindex, columnindex - 1));

					if (EBnum.equals("") || EBnum == null) {
						EBnum = "0";
					}

					double EBnumtemp = Double.valueOf(strTonum(EBnum));
					double costtemp = Double.valueOf(cost);

					tabbedPane.getPnlWall().setValue(EBnumtemp * costtemp,
							rowindex, columnindex + 1);
					tabbedPane.getPnlWall().setValue((int) EBnumtemp, rowindex,
							columnindex);
				}
			}
		});
	}

	public void windowEvent() {
		tabbedPane.getPnlWindow().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else if (projecttype == 1) {
					JOptionPane.showMessageDialog(frmHsproject,
							"베스에서불러오면 창호 데이터를 수정할수 없습니다.");
				} else {
					tabbedPane.getPnlWindow().addRow("window", selectedZoneNum,
							selectedWallNum);
					leftJTree.setTree(tabbedPane.getPnlZone(),
							tabbedPane.getPnlWall(), tabbedPane.getPnlWindow());

				}
			}
		});
		tabbedPane.getPnlWindow().eventReturnBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.getPnlZoneControl().setView("Wall");
			}
		});
		tabbedPane.getPnlWindow().eventAddTabel(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				int selectedWindowNum = tabbedPane.getPnlWindow()
						.getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlWindow()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlWindow().getLastColIndex();
				if (selectedColumn == lastColumn) {
					if (projecttype == 1) {
						JOptionPane.showMessageDialog(frmHsproject,
								"베스에서불러오면 존데이터를 수정할수 없습니다.");
					} else {
						tabbedPane.getPnlWindow().delRow(selectedWindowNum);
						leftJTree.setTree(tabbedPane.getPnlZone(),
								tabbedPane.getPnlWall(),
								tabbedPane.getPnlWindow());

					}
				}
				boolean[] editable = { false, true, true, false, false, false,
						false, false };
				tableEditerEvent(e, tabbedPane.getPnlWindow(), editable,
						"window");
			}
		});

		tabbedPane.getPnlWindow().eventKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char c = e.getKeyChar();

				if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
					e.consume(); // ignore event
					return;
				}

				if (tabbedPane.getPnlWindow().getSelectedColIndex() == 3) {
					int rowindex = tabbedPane.getPnlWindow()
							.getSelectedRowIndex();
					int columnindex = tabbedPane.getPnlWindow()
							.getSelectedColIndex();
					String EBnum;

					if (c == KeyEvent.VK_BACK_SPACE) {
						EBnum = String.valueOf(tabbedPane.getPnlWindow()
								.getTable().getValueAt(rowindex, columnindex));
						EBnum = (String) EBnum.subSequence(0,
								EBnum.length() - 1);
					} else {
						EBnum = String.valueOf(tabbedPane.getPnlWindow()
								.getTable().getValueAt(rowindex, columnindex))
								+ c;
					}

					String cost = String.valueOf(tabbedPane.getPnlWindow()
							.getTable().getValueAt(rowindex, columnindex - 1));

					if (EBnum.equals("") || EBnum == null) {
						EBnum = "0";
					}

					double EBnumtemp = Double.valueOf(strTonum(EBnum));
					double costtemp = Double.valueOf(cost);

					tabbedPane.getPnlWindow().setValue(EBnumtemp * costtemp,
							rowindex, columnindex + 1);
					tabbedPane.getPnlWindow().setValue((int) EBnumtemp,
							rowindex, columnindex);
				}
			}
		});
	}

	public void buildingEquipmentEvent() {
		tabbedPane.getPnlBE().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "용량(RT)", "정격효율",
							"단가(천원)" };

					vo.initpop();

					try {
						dao.load_system_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popBE = new PopUpBE(frmHsproject, header, vo
							.getSystempopData(), vo.getSystempopDataWithIndex());
					popBE.reload();
					popBEEvent();
					popBE.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlBE().eventAddTabel(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				int buildingEquipmentNum = tabbedPane.getPnlBE()
						.getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlBE()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlBE().getLastColIndex();
				if (selectedColumn == lastColumn) {
					tabbedPane.getPnlBE().delRow(buildingEquipmentNum);
					rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
							tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
				}
			}
		});

		tabbedPane.getPnlBE().eventKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char c = e.getKeyChar();

				if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
					e.consume(); // ignore event
					return;
				}

				if (tabbedPane.getPnlBE().getSelectedColIndex() == 4) {
					int rowindex = tabbedPane.getPnlBE().getSelectedRowIndex();
					int columnindex = tabbedPane.getPnlBE()
							.getSelectedColIndex();
					String EBnum;

					if (c == KeyEvent.VK_BACK_SPACE) {
						EBnum = String.valueOf(tabbedPane.getPnlBE().getTable()
								.getValueAt(rowindex, columnindex));
						EBnum = (String) EBnum.subSequence(0,
								EBnum.length() - 1);
					} else {
						EBnum = String.valueOf(tabbedPane.getPnlBE().getTable()
								.getValueAt(rowindex, columnindex))
								+ c;
					}

					String cost = String.valueOf(tabbedPane.getPnlBE()
							.getTable().getValueAt(rowindex, columnindex - 1));

					if (EBnum.equals("") || EBnum == null) {
						EBnum = "0";
					}

					double EBnumtemp = Double.valueOf(strTonum(EBnum));
					double costtemp = Double.valueOf(cost);

					tabbedPane.getPnlBE().setValue(EBnumtemp * costtemp,
							rowindex, columnindex + 1);
					tabbedPane.getPnlBE().setValue((int) EBnumtemp, rowindex,
							columnindex);
				}
			}

		});
	}

	public void equipmentetcEvent() {
		tabbedPane.getPnlEetc().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "전력소비량", "조명밀도", "단가(천원)" };

					vo.initpop();

					try {
						dao.load_etc_system_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popEetc = new PopUpEetc(frmHsproject, header, vo
							.getEtcsystempopData(), vo
							.getEtcsystempopDataWithIndex());
					popEetc.reload();
					popEetcEvent();
					popEetc.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlEetc().eventAddTabel(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				int equipmentetcNum = tabbedPane.getPnlEetc()
						.getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlEetc()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlEetc().getLastColIndex();
				if (selectedColumn == lastColumn) {
					tabbedPane.getPnlEetc().delRow(equipmentetcNum);
					rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
							tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
				}
			}
		});
		tabbedPane.getPnlEetc().eventKeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char c = e.getKeyChar();

				if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
					e.consume(); // ignore event
					return;
				}

				if (tabbedPane.getPnlEetc().getSelectedColIndex() == 3) {
					int rowindex = tabbedPane.getPnlEetc()
							.getSelectedRowIndex();
					int columnindex = tabbedPane.getPnlEetc()
							.getSelectedColIndex();
					String EBnum;

					if (c == KeyEvent.VK_BACK_SPACE) {
						EBnum = String.valueOf(tabbedPane.getPnlEetc()
								.getTable().getValueAt(rowindex, columnindex));
						EBnum = (String) EBnum.subSequence(0,
								EBnum.length() - 1);
					} else {
						EBnum = String.valueOf(tabbedPane.getPnlEetc()
								.getTable().getValueAt(rowindex, columnindex))
								+ c;
					}

					String cost = String.valueOf(tabbedPane.getPnlEetc()
							.getTable().getValueAt(rowindex, columnindex - 1));

					if (EBnum.equals("")) {
						EBnum = "0";
					}
					double EBnumtemp = Double.valueOf(EBnum);
					double costtemp = Double.valueOf(cost);

					tabbedPane.getPnlEetc().setValue(EBnumtemp * costtemp,
							rowindex, columnindex + 1);
					tabbedPane.getPnlEetc().setValue((int) EBnumtemp, rowindex,
							columnindex);
				}
			}
		});
	}

	public void renewalEnergyEvent() {
		tabbedPane.getPnlEnergy().btnEvent(0, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "모듈종류", "용량(kW)",
							"<html>가격<br></br>(kW/천원)</html>" };

					vo.initpop();

					try {
						dao.load_pv_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}

					popTable = new PopUpTable(frmHsproject, header, vo
							.getpvData());
					popTableEnvet(0);
					popTable.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlEnergy().btnEvent(1, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "집열판종류", "면적(m²)",
							"<html>가격<br></br>(㎡/천원)</html>" };

					vo.initpop();

					try {
						dao.load_solar_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}

					popTable = new PopUpTable(frmHsproject, header, vo
							.getsolarData());
					popTableEnvet(1);
					popTable.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlEnergy().btnEvent(2, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "용량(RT)",
							"<html>가격<br></br>(kW/천원)</html>" };

					vo.initpop();

					try {
						dao.load_geo_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popTable = new PopUpTable(frmHsproject, header, vo
							.getgeoData());
					popTableEnvet(2);
					popTable.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlEnergy().btnEvent(3, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "용량(kW)",
							"<html>가격<br></br>(kW/천원)</html>" };

					vo.initpop();

					try {
						dao.load_wind_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popTable = new PopUpTable(frmHsproject, header, vo
							.getwindData());
					popTableEnvet(3);
					popTable.setVisible(true);
				}
			}
		});
		tabbedPane.getPnlEnergy().btnEvent(4, new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (rightJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");

				} else {
					String[] header = { "제조사", "모델명", "용량(kW)", "열전비",
							"<html>가격<br></br>(kW/천원)</html>" };

					vo.initpop();

					try {
						dao.load_fuel_pop();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popTable = new PopUpTable(frmHsproject, header, vo
							.getfuelData());
					popTableEnvet(4);
					popTable.setVisible(true);
				}
			}
		});
	}

	public void economicsEvent() {
		// 이 패널은 returnBtn이 추가버튼
		tabbedPane.getPnlEconomics().eventReturnBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String[] temp = {"5","5","45","130","465","270","20"};
				
				tabbedPane.getPnlEconomics().addRow(temp);
			}
		});
		// 이 패널은 addBtn이 저장버튼
		tabbedPane.getPnlEconomics().eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popEconomics = new PopUpEconomics(frmHsproject, passive,
						system, light, newenergy, percentage);
				popEconomicsEvent();
				popEconomics.setVisible(true);
			}
		});
		tabbedPane.getPnlEconomics().eventAddTabel(new MouseAdapter() {
			public void mouseReleased(MouseEvent e) {
				int economicsNum = tabbedPane.getPnlEconomics()
						.getSelectedRowIndex();
				int selectedColumn = tabbedPane.getPnlEconomics()
						.getSelectedColIndex();
				int lastColumn = tabbedPane.getPnlEconomics().getLastColIndex();
				if (selectedColumn == lastColumn) {
					tabbedPane.getPnlEconomics().delRow(economicsNum);
				}
			}
		});
	}

	public void bottomButtonsEvent() {
		this.btnExport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else if (rightJTree.getSelectedIdx() == -1) {
					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");
				} else {
					// autosave = true;
					// Fill1();
					// Fill7();

					int leftJTreeIndex = leftJTree.getSelectedIdx();
					String projname = leftJTree.getSelectedItem(leftJTreeIndex);

					int rightJTreeIndex = rightJTree.getSelectedIdx();
					String sysname = rightJTree
							.getSelectedItem(rightJTreeIndex);

					FillF14(1, projname, sysname);

					File myFilename;
					chooser = new JFileChooser();
					chooser.addChoosableFileFilter(new OpenFileFilter("xls",
							"xls format"));
					chooser.setSelectedFile(new File(tabbedPane
							.getPnlProjectSummary().getAllData()[0] + ".xls"));
					int returnVal = chooser.showSaveDialog(frmHsproject);
					if (returnVal == JFileChooser.APPROVE_OPTION) {
						myFilename = chooser.getSelectedFile();

						Exportxls Export = new Exportxls(resultset, myFilename
								.getPath(), lastindx);
						try {
							Export.start();
						} catch (FileNotFoundException e1) {
							e1.printStackTrace();
						} catch (IOException e1) {
							e1.printStackTrace();
						}

						Export.structInfo();
						Export.result();
						Export.makeRChart();
						Export.makeLChart();
						Export.energyconsum();
						try {
							Export.closefile();
						} catch (IOException e1) {
							e1.printStackTrace();
						}
						ExportPDF Exportpdf = new ExportPDF();
						Exportpdf.setFilePath(myFilename.getPath());
						try {
							Exportpdf.ConvertTopdf1();
						} catch (ConnectException e1) {
							e1.printStackTrace();
						}
						ExportCsv csv = new ExportCsv();
						csv.setFilePath(myFilename.getPath());
						csv.Start(resultset.csvData());
					}
				}
			}
		});
		this.btnGraph.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (leftJTree.getSelectedIdx() == -1) {

					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 건축요소가 없습니다.");

				} else if (rightJTree.getSelectedIdx() == -1) {
					JOptionPane.showMessageDialog(frmHsproject,
							"선택된 시스템이 없습니다.");
				} else {
					// autosave = true;
					// Fill1();
					// Fill7();

					int leftJTreeIndex = leftJTree.getSelectedIdx();
					String projname = leftJTree.getSelectedItem(leftJTreeIndex);

					int rightJTreeIndex = rightJTree.getSelectedIdx();
					String sysname = rightJTree
							.getSelectedItem(rightJTreeIndex);

					FillF14(1, projname, sysname);

					vo.initproject_list();
					try {
						dao.load_project_list();
					} catch (SQLException e1) {
						e1.printStackTrace();
					}

					popSTP = new PopUpSelectThreeProject(frmHsproject, vo
							.ProjectList(), leftJTree.getSelectedItem());
					popSTPEvent();
					popSTP.setVisible(true);
				}
			}
		});
	}

	public void selectProjectEvent() {

		selectProject.btnOKListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String filepath = "c:\\bess\\output\\" + "project_total_"
						+ selectProject.getSelectedname() + ".csv";
				File f = new File(filepath);
				if (!f.isFile()) {
					JOptionPane.showMessageDialog(frmHsproject, filepath
							+ "로 1,2차 에너지 소요량 데이터를 저장한후 다시 시도해 주세요.");
					selectProject.dispose();
					popIP.dispose();
					lcomboBoxSelected = true;
					return;
				}

				leftJTree.addComboBox(projectname);
				prjIdx = leftJTree.getcomboBoxSize();
				leftJTree.setComboBoxItem(prjIdx - 1);

				selectProject.dispose();
				popIP.dispose();

				Fill4();
				Fill3(selectProject.getSelectedname());
				Fill3_1(filepath, prjIdx);
				tabbedPane.getPnlProjectSummary().setEditable(false);
				tabbedPane.getPnlProjectSummary().setTextFE(vo.getFE_econ());
				tabbedPane.getPnlProjectSummary().setTextSE(vo.getSE_econ());
				tabbedPane.getPnlProjectSummary().setText(0, projectname);
				prjIdx = leftJTree.getSelectedIdx();
				projecttype = 1;
				lcomboBoxSelected = true;
			}
		});

		selectProject.btnCloseListener(closePopUp(selectProject));
	}

	public void popSTPEvent() {

		popSTP.btnOKListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES = new PopUpTotalEnergySpend(frmHsproject);
				selectProjects = popSTP.getSelectedname();
				popTES.setDataLabel(selectProjects);
				// unit은 double
				// 나머지 인수는 ArrayList<double[]>로 프로젝트 3개의 1월~12월까지의 데이터가 들어가야함
				//
				vo.initegraph();
				try {
					double[] area = { 0, 0, 0 };

					int projectIndex = vo.getProjectindex(selectProjects[0]);
					dao.load_second_e_graph(projectIndex);
					double[] temp1 = vo.getSE_Graph_eachsum();
					// TODO 전체 면적을 실제 값으로 불러와야함. 수정요
					area[0] = 13;

					vo.initegraph();
					projectIndex = vo.getProjectindex(selectProjects[1]);
					dao.load_second_e_graph(projectIndex);
					double[] temp2 = vo.getSE_Graph_eachsum();

					// TODO 전체 면적을 실제 값으로 불러와야함. 수정요
					area[1] = 11;

					vo.initegraph();
					projectIndex = vo.getProjectindex(selectProjects[2]);
					dao.load_second_e_graph(projectIndex);
					double[] temp3 = vo.getSE_Graph_eachsum();

					// TODO 전체 면적을 실제 값으로 불러와야함. 수정요
					area[2] = 12;

					resultset.setEnergyspendData(temp1, temp2, temp3);
					resultset.setArea(area);
				} catch (SQLException e1) {
					e1.printStackTrace();
				}

				popTES.setEnergySpendData(resultset.getEnergyspendData());
				popTES.setHeatProduceData(resultset.getMakeHeatData());
				popTES.setElectroProduceData(resultset.getMakeelecData());
				popTES.setEnergySpendUnitArea(resultset.getArea());
				popTES.dataAlgorithm();
				popTESEvnet();
				popTES.setVisible(true);
				popSTP.dispose();
			}
		});

		popSTP.btnCloseListener(closePopUp(popSTP));
	}

	public void popIPEvent() {
		popIP.LoadBESSListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				// 프로젝트 리스트 불러오는 부분

				selectProject = new PopUpSelectProject(popIP, vo.getBessList());
				selectProjectEvent();
				selectProject.setVisible(true);
			}
		});

		popIP.StandartModelListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {

				Path_Loader PL = new Path_Loader(frmHsproject, STATE_Load);

				if (PL.getfileName() == null) {
					return;
				}

				Importkinddata IKD = new Importkinddata(PL.getFileDirectory()
						+ PL.getfileName());

				System.out.println(PL.getFileDirectory() + PL.getfileName());

				try {
					IKD.start();
				} catch (FileNotFoundException e1) {
					e1.printStackTrace();
				} catch (IOException e1) {
					e1.printStackTrace();
				}
				String[][] temp = new String[12][5];
				String tempCO2;

				temp = IKD.getDataFromXLS();
				tempCO2 = IKD.getDataFromXLSCO2();

				if (isLeftTreeSelectnull == true) {
					prjIdx = leftJTree.getcomboBoxSize();
					leftJTree.delComboBox(prjIdx - 1);
					isLeftTreeSelectnull = false;
				}
				leftJTree.addComboBox(projectname);
				prjIdx = leftJTree.getcomboBoxSize();
				leftJTree.setComboBoxItem(prjIdx - 1);

				vo.initegraph();
				vo.setE_Graph(prjIdx, null, temp, tempCO2);
				projecttype = 2;
				popIP.dispose();

				tabbedPane.getPnlProjectSummary().setEditablemodel(true);
				tabbedPane.getPnlProjectSummary().setTextFE(vo.getFE_econ());
				tabbedPane.getPnlProjectSummary().setTextSE(vo.getSE_econ());
				tabbedPane.getPnlProjectSummary().setText(0, projectname);
				lcomboBoxSelected = true;
			}
		});

		popIP.InputDataListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				Fill2();
				if (isLeftTreeSelectnull == true) {
					prjIdx = leftJTree.getcomboBoxSize();
					leftJTree.delComboBox(prjIdx - 1);
					isLeftTreeSelectnull = false;
				}
				leftJTree.addComboBox(projectname);
				prjIdx = leftJTree.getcomboBoxSize();
				leftJTree.setComboBoxItem(prjIdx - 1);

				popIP.dispose();
				projecttype = 3;
				tabbedPane.getPnlProjectSummary().setEditable(true);
				tabbedPane.getPnlProjectSummary().setText(0, projectname);
				lcomboBoxSelected = true;
			}
		});
	}

	public void popTableEnvet(final int index) {
		popTable.eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popIE = new PopUpInsertEquipment(frmHsproject, popTable
						.getHeader());
				popIE.setState(2);
				PopUpIEEvent(index);
				popIE.setVisible(true);
			}
		});
		popTable.eventSaveBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				String temp = null;
				int selectedRowIndex = popTable.getSelectedRowIndex();
				if (index == 0) {
					temp = vo.getpvDataindex().get(selectedRowIndex);
				} else if (index == 1) {
					temp = vo.getsolarDataIndex().get(selectedRowIndex);
				} else if (index == 2) {
					temp = vo.getgeoDataIndex().get(selectedRowIndex);
				} else if (index == 3) {
					temp = vo.getwindDataIndex().get(selectedRowIndex);
				} else if (index == 4) {
					temp = vo.getfuelDataIndex().get(selectedRowIndex);
				}

				tabbedPane.getPnlEnergy().setValue_idx(index, temp);
				tabbedPane.getPnlEnergy().setModelName(index,
						popTable.getModelName(selectedRowIndex));
				popTable.dispose();
				rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
						tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
			}
		});
		popTable.eventCloseBtn(closePopUp(popTable));
	}

	public void popBEEvent() {
		popBE.eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popIE = new PopUpInsertEquipment(frmHsproject, popBE
						.getHeader());
				popIE.setState(1);
				PopUpIEEvent(0);
				popIE.setVisible(true);
			}
		});
		popBE.eventSaveBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.getPnlBE().addRow(popBE.getData());
				popBE.dispose();
				rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
						tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
			}
		});
		popBE.eventCloseBtn(closePopUp(popBE));

		popBE.comboBoxItemListener(new ItemListener() {

			public void itemStateChanged(ItemEvent arg0) {
				popBE.reload();
				popBE.changeHader();
			}
		});
	}

	public void popEetcEvent() {
		popEetc.eventAddBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popIE = new PopUpInsertEquipment(frmHsproject, popEetc
						.getHeader());
				popIE.setState(0);
				PopUpIEEvent(0);
				popIE.setVisible(true);
			}
		});
		popEetc.eventSaveBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				tabbedPane.getPnlEetc().addRow(popEetc.getData());
				// tabbedPane.getPnlBE().addRow(popEetc.getData());
				popEetc.dispose();
				rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
						tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
			}
		});
		popEetc.eventCloseBtn(closePopUp(popEetc));

		popEetc.comboBoxItemListener(new ItemListener() {

			public void itemStateChanged(ItemEvent arg0) {
				popEetc.reload();
			}
		});
	}

	public void PopUpIEEvent(final int index) {
		popIE.eventSaveBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (popIE.getState() == 2) {// Renewal에서 온 이벤트
					popTable.addRow(popIE.getData());
					try {
						if (index == 0) {
							dao.save_pv_pop_row(popIE.getData());
						} else if (index == 1) {
							dao.save_solar_pop_row(popIE.getData());
						} else if (index == 2) {
							dao.save_geo_pop_row(popIE.getData());
						} else if (index == 3) {
							dao.save_wind_pop_row(popIE.getData());
						} else if (index == 4) {
							dao.save_fuel_pop_row(popIE.getData());
						}
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popIE.dispose();
				} else if (popIE.getState() == 1) {// BE에서 온 이벤트
					popBE.addRow(popIE.getData());
					try {
						dao.save_system_pop(
								popBE.getComboboxSelectedContentName(),
								popIE.getData());
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popIE.dispose();
				} else if (popIE.getState() == 0) {
					popEetc.addRow(popIE.getData());
					try {
						dao.save_etc_system_pop(
								popEetc.getComboboxSelectedContentName(),
								popIE.getData());
					} catch (SQLException e1) {
						e1.printStackTrace();
					}
					popIE.dispose();
				}
			}
		});
		popIE.eventCloseBtn(closePopUp(popIE));
	}

	public void popEconomicsEvent() {
		popEconomics.eventCloseBtn(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent arg0) {
				if (popEconomics.getPercentage().equals("")) {
					popEconomics.setPercentage("0");
				}
				percentage = Integer.valueOf(popEconomics.getPercentage());

				popEconomics.dispose();
			}
		});
		popEconomics.eventLightRBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				light = !light;
			}
		});
		popEconomics.eventPassiveRBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				passive = !passive;
			}
		});
		popEconomics.eventRenewalRBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				newenergy = !newenergy;
			}
		});
		popEconomics.eventSystemRBtn(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				system = !system;
			}
		});

		popEconomics.eventkeyListener(new KeyAdapter() {
			public void keyTyped(KeyEvent e) {
				char c = e.getKeyChar();

				if (((c < '0') || (c > '9')) && (c != KeyEvent.VK_BACK_SPACE)) {
					e.consume();
					return;
				}

				if (popEconomics.getPercentage().length() >= 2) {
					e.consume();
					return;
				}

				if (popEconomics.getPercentage().length() == 1
						&& popEconomics.getPercentage().equals("0")) {
					popEconomics.setPercentage("");
				}

			}
		});
	}

	public void popTESEvnet() {
		popTES.eventbtnClose(closePopUp(popTES));
		popTES.eventbtnNPV(new ActionListener() {
			public void actionPerformed(ActionEvent e) {				
				popOTable = new PopUpOptimizationTable(frmHsproject, popTES);
				popOTable.setstate(selectedpriority);
				popOTable.setDataSet(resultset.getDataset());
				popOTableEvent();
				popOTable.setVisible(true);
				
				// TODO 
			}
		});
		popTES.eventbtnEnergyProduce(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.setKind(true);
				popTES.btnImgSetting();
				popTES.setRBtnUnitAreaEnabled(false);
				popTES.setRBtnTotalSelect(true);
				popTES.drawChart();
			}
		});
		popTES.eventbtnEnergySpend(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.setKind(false);
				popTES.btnImgSetting();
				popTES.setRBtnUnitAreaEnabled(true);
				popTES.drawChart();
			}
		});
		popTES.eventrbtnTotal(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.drawChart();

			}
		});
		popTES.eventrbtnUnitArea(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.drawChart();
			}
		});

		popTES.eventrbtnMonth(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.drawChart();
			}
		});
		popTES.eventrbtnYear(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popTES.drawChart();
			}
		});
	}

	public void popNPVChartEvent() {
		popNPVChart.eventbtnClose(closePopUp(popNPVChart));
		popNPVChart.eventbtnOpenResult(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popNPVChart.dispose();
				popOTable = new PopUpOptimizationTable(frmHsproject, popTES);
				popOTable.setstate(selectedpriority);
				popOTable.setDataSet(resultset.getDataset());
				popOTableEvent();
				popOTable.setVisible(true);
			}
		});
	}

	public void popOTableEvent() {
		popOTable.eventbtnResult(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popOTable.dispose();
				pop3DChart = new PopUp3DChart(frmHsproject, popTES);
				ArrayList<double[]> data = new ArrayList<double[]>();
				double[][] value = resultset.getRadarchart();

				for (int i = 0; i < value.length; i++) {
					double[] temp = new double[value[0].length];
					for (int j = 0; j < value[i].length; j++) {
						temp[j] = value[i][j];
					}
					data.add(temp);
				}
				// pop3DChart.setDataLabel(selectProjects);
				pop3DChart.setData(data);
				pop3DChart.removeChart();
				pop3DChart.anmationChart();
				// 3dChart에 데이터를 넣어야 하는 부분 끝
				pop3DChartEvent();
				pop3DChart.setVisible(true);
			}
		});
		popOTable.eventbtnChange(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption = new PopUpOTOption(popOTable, popOTable
						.getOptionBtn());
				popUpOTOptionEvent();
				popUpOTOption.setVisible(true);

			}
		});
		popOTable.eventbtnNPVResult(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popOTable.dispose();			
				popNPVChart = new PopUpNPVChart(frmHsproject, popTES);
				// 여기다가 채우면되
				// xData는 double[] 로 x축의 값을
				// yData는 double[] 로 y축의 값을 넣어주면 되
				//
				popNPVChart.setxData(resultset.getNPVx());
				popNPVChart.setyData(resultset.getNPVy());
				popNPVChart.setDataLabel(selectProjects);
				popNPVChart.repaintChart();
				popNPVChartEvent();
				popNPVChart.setVisible(true);
			}
		});
		popOTable.eventbtnClose(closePopUp(popOTable));
	}

	public void pop3DChartEvent() {
		pop3DChart.eventbtnClose(closePopUp(pop3DChart));
		pop3DChart.eventbtnOpenTable(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				pop3DChart.dispose();
				popRTable = new PopUpResultTable(popTES,resultset.resultChart());
				popRTableEvent();
				popRTable.setVisible(true);
			}
		});
	}

	public void popRTableEvent() {
		popRTable.eventbtnClose(closePopUp(popRTable));
		popRTable.eventbtnOpenGraph(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popRTable.dispose();
				pop3DChart = new PopUp3DChart(frmHsproject, popTES);
				ArrayList<double[]> data = new ArrayList<double[]>();
				double[][] value = resultset.getRadarchart();
				for (int i = 0; i < value.length; i++) {
					double[] temp = new double[value[0].length];
					for (int j = 0; j < value[i].length; j++) {
						temp[j] = value[i][j];
					}
					data.add(temp);
				}

				// pop3DChart.setDataLabel(selectProjects);
				pop3DChart.setData(data);
				pop3DChart.removeChart();
				pop3DChart.repaintChart();
				// 3dChart에 데이터를 넣어야 하는 부분 끝
				pop3DChartEvent();
				pop3DChart.setVisible(true);
			}
		});
	}

	public void popUpOTOptionEvent() {
		popUpOTOption.eventbtnEnergProduce(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("에너지생산량");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 0);
				selectedpriority = "에너지생산량";
				popUpOTOption.dispose();
			}
		});
		popUpOTOption.eventbtnInitInvestment(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("초기투자비");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 1);
				selectedpriority = "초기투자비";
				popUpOTOption.dispose();
			}
		});
		popUpOTOption.eventbtnNPV(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("순현재가치(NPV)");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 2);
				selectedpriority = "순현재가치(NPV)";
				popUpOTOption.dispose();
			}
		});
		popUpOTOption.eventbtnPayBackPeriod(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("투자회수기간");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 3);
				selectedpriority = "투자회수기간";
				popUpOTOption.dispose();
			}
		});
		popUpOTOption.eventbtnRenewalRating(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("신재생에너지 이용률");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 4);
				selectedpriority = "신재생에너지 이용률";
				popUpOTOption.dispose();
			}
		});
		popUpOTOption.eventbtnSustainingCosts(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				popUpOTOption.setcurrentbtn("유지관리비");
				popOTable.setstate(popUpOTOption.getCurrentbtn());
				popOTable.settextt(popOTable.getcuurent() + 5);
				selectedpriority = "유지관리비";
				popUpOTOption.dispose();
			}
		});
	}

	public ActionListener closePopUp(final JDialog dialog) {
		ActionListener al = new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				dialog.dispose();
			}
		};
		return al;
	}

	// ///////////////////////////////////////////////////////Fill/////////////////////////////////////////////////////////
	/**
	 * 초기에 건축요소 불러오는 부분 done
	 */
	private void FillC1() {
		try {
			dao.load_project_list();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		leftJTree.setComboBoxList(vo.ProjectList());
	}

	/**
	 * 초기에 시스템 불러오는 부분 done
	 */
	private void FillC2() {
		try {
			dao.load_category();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		rightJTree.setComboBoxList(vo.CategoryList());
	}

	/**
	 * 기존 데이터 저장하는 부분 Fill#1
	 * 
	 */
	private void Fill1() {
		// 건축요소의 기존 데이터를 VO로 전달

		String[] ProjectSummaryTemp = tabbedPane.getPnlProjectSummary()
				.getAllData();
		ArrayList<String[]> PnlZoneTemp = tabbedPane.getPnlZone().getData();
		ArrayList<String[]> PnlWallTemp = tabbedPane.getPnlWall().getData();
		ArrayList<String[]> PnlWindowTemp = tabbedPane.getPnlWindow().getData();

		String selecteItemName = leftJTree.getSelectedItem(prjIdx);
		int projectIndex = vo.getProjectindex(selecteItemName);

		lastindx = projectIndex;

		vo.initproject();
		if (projectIndex == -1) {
			try {
				projectIndex = dao.find_empty_project_index();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else {
			try {
				dao.delete_project(projectIndex);
				dao.delete_first_e_graphToProjid(projectIndex);
				dao.delete_second_e_graphToProjid(projectIndex);
				dao.delete_econsumToProjid(projectIndex);
				dao.delete_zoneToProjid(projectIndex);
				dao.delete_wallToProjid(projectIndex);
				dao.delete_windowToProjid(projectIndex);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		vo.setProjectData(ProjectSummaryTemp, PnlZoneTemp, PnlWallTemp,
				PnlWindowTemp, leftJTree.getSelectedWeather(), projectIndex,
				projecttype);

		// VO에서 DAO를 통해 DATABASE로 저장

		try {
			dao.save_project();
			dao.save_first_e_graph(projectIndex);
			dao.save_second_e_graph(projectIndex);
			dao.save_econsum();
			dao.save_zone();
			dao.save_wall();
			dao.save_window();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		vo.initegraph();
	}

	/**
	 * 건축요소 초기화 하는 부분 Fill#2 Done
	 */
	private void Fill2() {
		// 테이블을 원래상태로 초기화 시킨
		tabbedPane.getPnlProjectSummary().initallcomp();
		tabbedPane.getPnlZone().initallcomp();
		tabbedPane.getPnlWall().initallcomp();
		tabbedPane.getPnlWindow().initallcomp();

		// 트리를 원래 상태로 초기화 시킴
		leftJTree.delalltreecomp();
	}

	/**
	 * VO에서 메인으로 데이터 가져옴 BESS Fill#3
	 */
	private void Fill3(String name) {
		// VO에서 메인으로 데이터 가져옴
		int projectIndex = vo.getBessProjectindex(name);

		dao.bess_list();
		try {
			dao.load_bess_project(projectIndex);
			dao.load_bess_zone_wall_window(projectIndex);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		dao.OTRE_DAO();

		String[] ProjectData = vo.getBessProjectData(projectIndex);
		tabbedPane.getPnlProjectSummary().setAllText(ProjectData, null);

		// 임시Fill#
		ArrayList<String[]> ZoneData = vo.getBessZoneData(projectIndex);
		tabbedPane.getPnlZone().setAlldata(ZoneData);

		ArrayList<String[]> WallData = vo.getBessWallData(projectIndex);
		// ArrayList<String[]> WallDataindexlist =
		// vo.getWallDataindexlist(projectIndex);
		tabbedPane.getPnlWall().setAlldata(WallData);
		// tabbedPane.getPnlWall().setIndexList(WallDataindexlist);

		ArrayList<String[]> WindowData = vo.getBessWindowData(projectIndex);
		// ArrayList<String[]> WindowDataindexlist =
		// vo.getWindowDataindexlist(projectIndex);
		tabbedPane.getPnlWindow().setAlldata(WindowData);
		// tabbedPane.getPnlWindow().setIndexList(WindowDataindexlist);

		// ArrayList<String[]> ZoneData = vo.getBessZoneData(projectIndex);
		// tabbedPane.getPnlZone().setAlldata(ZoneData);
		//
		// ArrayList<String[]> WallData = vo.getWallData(projectIndex);
		// ArrayList<String[]> WallDataindexlist =
		// vo.getWallDataindexlist(projectIndex);
		// tabbedPane.getPnlWall().setAlldata(WallData);
		// tabbedPane.getPnlWall().setIndexList(WallDataindexlist);
		//
		// ArrayList<String[]> WindowData = vo.getWindowData(projectIndex);
		// ArrayList<String[]> WindowDataindexlist =
		// vo.getWindowDataindexlist(projectIndex);
		// tabbedPane.getPnlWindow().setAlldata(WindowData);
		// tabbedPane.getPnlWindow().setIndexList(WindowDataindexlist);

		leftJTree.setTreeBess(tabbedPane.getPnlZone(), tabbedPane.getPnlWall(),
				tabbedPane.getPnlWindow());
		leftJTreeSelectEvent();
	}

	private void Fill3_1(String filepath, int projectindex) {
		vo.initegraph();

		String[][] temp = new String[12][5];
		String[][] temp1 = new String[12][5];

		CSVReader reader;
		java.util.List<String[]> myEntries = null;
		try {
			reader = new CSVReader(new FileReader(filepath));
			myEntries = reader.readAll();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		for (int i = 0; i < 12; i++) {
			temp[i][0] = myEntries.get(41 + i)[1 + 1];
			temp1[i][0] = myEntries.get(22 + i)[1 + 1];
			temp[i][1] = myEntries.get(41 + i)[1 + 0];
			temp1[i][1] = myEntries.get(22 + i)[1 + 0];
			temp[i][2] = myEntries.get(41 + i)[1 + 3];
			temp1[i][2] = myEntries.get(22 + i)[1 + 3];
			temp[i][3] = myEntries.get(41 + i)[1 + 2];
			temp1[i][3] = myEntries.get(22 + i)[1 + 2];
			temp[i][4] = myEntries.get(41 + i)[1 + 4];
			temp1[i][4] = myEntries.get(22 + i)[1 + 4];
		}

		vo.setE_Graph(projectindex, temp, temp1, "0");
	}

	/**
	 * // DAO로 BESS_DB에서 VO로 데이터 가져옴 Fill#4
	 */
	private void Fill4() {
		// DAO로 DB에서 VO로 데이터 가져옴
		dao.bess_list();

		int bess_project_idx = 0; // bess DB내의 불러오려는 project index값.

		try {
			dao.load_bess_project(bess_project_idx);
			dao.load_bess_zone_wall_window(bess_project_idx);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		dao.OTRE_DAO();
	}

	/**
	 * VO 삭제 Fill#5 Done
	 */
	private void Fill5() {
		// 건축요소 부분 VO 초기화
		vo.initproject();
		try {
			dao.load_project_list();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		int projectIndex = vo.getProjectindex(leftJTree.getSelectedItem());
		try {
			dao.delete_project(projectIndex);
			dao.delete_first_e_graphToProjid(projectIndex);
			dao.delete_second_e_graphToProjid(projectIndex);
			dao.delete_econsumToProjid(projectIndex);
			dao.delete_zoneToProjid(projectIndex);
			dao.delete_wallToProjid(projectIndex);
			dao.delete_windowToProjid(projectIndex);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * DAO에서 VO로 불러옴Fill#6 전체데이터
	 */
	private void Fill6(String name) {
		vo.initproject();
		vo.initegraph();
		int projectIndex = 0;
		try {
			dao.load_project_list();
			dao.load_project();
			projectIndex = vo.getProjectindex(name);
			dao.load_first_e_graph(projectIndex);
			dao.load_second_e_graph(projectIndex);
			dao.load_econsum();
			dao.load_zone();
			dao.load_wall();
			dao.load_window();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		String[] ProjectData = vo.getProjectData(projectIndex);
		String[] EconData = vo.getEcosumData(projectIndex);
		tabbedPane.getPnlProjectSummary().setAllText(ProjectData, EconData);
		leftJTree.setSelectedWeather(ProjectData[7]);
		projecttype = Integer.valueOf(ProjectData[8]);

		ArrayList<String[]> ZoneData = vo.getZoneData(projectIndex);
		ArrayList<String[]> ZoneDataindexlist = vo
				.getZoneDataindexlist(projectIndex);
		tabbedPane.getPnlZone().setAlldata(ZoneData);
		tabbedPane.getPnlZone().setIndexList(ZoneDataindexlist);

		ArrayList<String[]> WallData = vo.getWallData(projectIndex);
		ArrayList<String[]> WallDataindexlist = vo
				.getWallDataindexlist(projectIndex);
		tabbedPane.getPnlWall().setAlldata(WallData);
		tabbedPane.getPnlWall().setIndexList(WallDataindexlist);

		ArrayList<String[]> WindowData = vo.getWindowData(projectIndex);
		ArrayList<String[]> WindowDataindexlist = vo
				.getWindowDataindexlist(projectIndex);
		tabbedPane.getPnlWindow().setAlldata(WindowData);
		tabbedPane.getPnlWindow().setIndexList(WindowDataindexlist);

		leftJTree.setTree(tabbedPane.getPnlZone(), tabbedPane.getPnlWall(),
				tabbedPane.getPnlWindow());
		leftJTreeSelectEvent();
	}

	/**
	 * // 기존 데이터 저장하는 부분 시스템 부분 Fill#7
	 */
	private void Fill7() {

		ArrayList<String[]> PnlBETemp = tabbedPane.getPnlBE().getData();
		String[] PnlEnergyTemp = tabbedPane.getPnlEnergy().getData();
		ArrayList<String[]> PnlEetcTemp = tabbedPane.getPnlEetc().getData();

		String selecteItemName = rightJTree.getSelectedItem(sysIdx);
		int systemIndex = vo.getCategoryindex(selecteItemName);

		vo.initSystem();
		if (systemIndex == -1) {
			try {
				systemIndex = dao.find_empty_category_index();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		} else {
			try {
				dao.delete_category(systemIndex);
				dao.delete_renewableToCategid(systemIndex);
				dao.delete_etc_systemToCategid(systemIndex);
				dao.delete_systemToCategid(systemIndex);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		vo.setSystemData(PnlBETemp, PnlEnergyTemp, PnlEetcTemp, systemIndex,
				selecteItemName);

		try {
			dao.save_category();
			dao.save_renewable();
			dao.save_etc_system();
			dao.save_system();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * // VO에서 메인으로 가져옴Fill#9
	 */
	private void Fill9(String name) {
		vo.initSystem();
		try {
			dao.load_category();
			dao.load_system();
			dao.load_etc_system();
			dao.load_renewable();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		int categoryIndex = vo.getCategoryindex(name);
		ArrayList<String[]> SystemData = vo.getSystemData(categoryIndex);
		tabbedPane.getPnlBE().setAlldata(SystemData);
		ArrayList<String[]> Etc_SystemData = vo
				.getEtc_systemData(categoryIndex);
		tabbedPane.getPnlEetc().setAlldata(Etc_SystemData);

		String[] RenewableData = vo.getRenewableData(categoryIndex);
		tabbedPane.getPnlEnergy().setAllData(RenewableData);
		tabbedPane.getPnlEnergy().setModelName(
				vo.getNewenergyList(categoryIndex));

		rightJTree.setTreeSystem(tabbedPane.getPnlBE(),
				tabbedPane.getPnlEetc(), tabbedPane.getPnlEnergy());
		rightJTreeSelectEvent();
	}

	/**
	 * 시스템 초기화 하는 부분 Fill#10 done
	 */
	private void Fill10() {
		// 테이블을 원래상태로 초기화 시킨
		tabbedPane.getPnlBE().initallcomp();
		tabbedPane.getPnlEetc().initallcomp();
		tabbedPane.getPnlEnergy().initallcomp();

		// 트리를 원래 상태로 초기화 시킴
		rightJTree.delalltreecomp();
	}

	/**
	 * DAO,VO 삭제 Fill#11 Done
	 */
	private void Fill11() {
		vo.initSystem();
		try {
			dao.load_category();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		int categoryIndex = vo.getCategoryindex(rightJTree.getSelectedItem());
		try {
			dao.delete_category(categoryIndex);
			dao.delete_systemToCategid(categoryIndex);
			dao.delete_etc_systemToCategid(categoryIndex);
			dao.delete_renewableToCategid(categoryIndex);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	/**
	 * // DAO에서 목록을 새로 불러옴 Fill#12 리스트 Done
	 */
	private void Fill12() {
		try {
			// autosave=false;
			vo.initproject();
			dao.load_project_list();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		leftJTree.setComboBoxList(vo.ProjectList());
	}

	/**
	 * DAO에서 목록을 새로 불러올 Fill#13 Done
	 */
	private void Fill13() {

		try {
			vo.initSystem();
			dao.load_category();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		rightJTree.setComboBoxList(vo.CategoryList());

	}

	private void FillF14(int type, String projectname, String sysname){

		String[] ProjectSummaryTemp = tabbedPane.getPnlProjectSummary().getAllData();
		ArrayList<String[]> PnlZoneTemp = tabbedPane.getPnlZone().getData();
		ArrayList<String[]> PnlWallTemp = tabbedPane.getPnlWall().getData();
		ArrayList<String[]> PnlWindowTemp = tabbedPane.getPnlWindow().getData();
		
		ArrayList<String[]> PnlBETemp = tabbedPane.getPnlBE().getData();
		String[] PnlEnergyTemp = tabbedPane.getPnlEnergy().getData();
		ArrayList<String[]> PnlEetcTemp = tabbedPane.getPnlEetc().getData();
		
		String[][] FE_GraphData = vo.getFE_Graph();
		String[][] SE_GraphData = vo.getSE_Graph();

		resultset = new Result(leftJTree.getSelectedWeather());
		resultset.setCondition(passive, system, light, newenergy, percentage);
		resultset.setProjectData(ProjectSummaryTemp, PnlZoneTemp, PnlWallTemp, PnlWindowTemp, FE_GraphData, SE_GraphData);
		resultset.setSystemData(PnlBETemp, PnlEnergyTemp, PnlEetcTemp);
		resultset.setEconomic(tabbedPane.getPnlEconomics().getData());
		try {
			resultset.start(projectname, sysname);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 중복체크 할 부분 FillF#1 Done
	 */
	private boolean FillF1(String projectName) {

		if (projectName == null) {
			return true;
		}
		vo.initproject();
		try {
			dao.load_project_list();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		if (vo.ProjectDuplicateCheck(projectName)) {
			JOptionPane.showMessageDialog(frmHsproject, "중복입니다.");
			return true;
		}

		return false;
	}

	/**
	 * FillF#2 중복체크 할 부분 Done
	 */
	private boolean FillF2(String CategoryName) {
		if (CategoryName == null) {
			return true;
		}

		try {
			dao.load_category();
		} catch (SQLException e) {
			e.printStackTrace();
		}

		if (vo.CategoryDuplicateCheck(CategoryName)) {
			JOptionPane.showMessageDialog(frmHsproject, "중복입니다.");
			return true;
		}

		return false;
	}

	private void projecteditable() {
		if (projecttype == 1) {
			tabbedPane.getPnlProjectSummary().setEditable(false);
		} else if (projecttype == 2) {
			tabbedPane.getPnlProjectSummary().setEditablemodel(true);
		} else if (projecttype == 3) {
			tabbedPane.getPnlProjectSummary().setEditable(true);
		} else {

		}

	}

	private String strTonum(String str) {

		if (str == null) {
			return "0";
		}

		String result = "";

		for (int i = 0; i < str.length(); i++) {
			if (Character.isDigit(str.charAt(i))) {
				result = result + str.charAt(i);
			}
		}

		if (result.equals("")) {
			return "0";
		}
		return result;
	}

}